<?php
	class Pendidikan_model extends Model{
		function Pendidikan_model(){
			parent::Model();
		}
        
        function list_pendidikan($nip="",$where="", $order="", $ro=false) {
        	if ($nip=="") {
        		return "";
        	} else {
                $this->db->where(array('nip' => $nip));
                $this->db->or_where(array('nip_baru' => $nip));
        	}
        	
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('nama asc');
            } else {
                $this->db->order_by($order);
            }
            $this->db->from('pegawai');
            $q = $this->db->get();

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>Jenjang Pendidikan</th>
                    <th>Sekolah/Universitas</th>
                    <th>Jurusan</th>
                    <th>Nama Kepala Sekolah/Univ</th>
                    <th>Nomor STTB/Ijazah</th>
                    <th>Tanggal STTB/Ijazah</th>
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
                
                //data pendidikan terakhir
                $this->db->from('pendidikan');
                $this->db->where(array('id_pegawai' => $row->idspg_pegawai));
                $this->db->select('idspg_pendidikan, nama as pend_terakhir, id_jurusan, nama_sekolah_universitas, '.
                                  'no_ijazah, tgl_ijazah, nama_kepsek');
                $q1 = $this->db->get();
                if ($q1->num_rows() > 0) {
                	foreach ($q1->result() as $row1) {
		                if ($row1->id_jurusan<>0) {
		                	$jurusan = Datum_model::getData('nama', 'jurusan', array('idspg_jurusan' => $row1->id_jurusan));
		                } else {
		                	$jurusan = '-';
		                }
		                
		                //$jenis_kepegawaian = Datum_model::getData('nama', 'jenis_kepegawaian', array('idspg_jenis_kepegawaian' => $row->id_jenis_kepegawaian));
		                //$unit_kerja = Datum_model::getData('nama', 'unit_kerja', array('idspg_unit_kerja' => $row->id_unit_kerja));
		                
//		                $pangkat_terakhir = Datum_model::getLatestData('id_golongan', 'pengangkatan_pangkat', array('id_pegawai' => $row->idspg_pegawai));
//		                $this->db->select('nama, pangkat');
//		                $this->db->where(array('idspg_golongan' => $pangkat_terakhir));
//						$query = $this->db->get('golongan');
//						if ($query->num_rows() > 0) {
//							$r = $query->row();
//							$pangkat = $r->nama.' - '.$r->pangkat;
//						} else {
//							$pangkat = '-';
//						}
//		
//						$jabatan_terakhir = Datum_model::getLatestData('id_jabatan', 'pengangkatan_jabatan', array('id_pegawai' => $row->idspg_pegawai));
//		                $jabatan = Datum_model::getData('nama', 'jabatan', array('idspg_jabatan' => $jabatan_terakhir));
		                
		                $s .= "
		              <tr class=\"$kelas\" id=\"row-".$row->idspg_pegawai."\" >
		                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
		                <td>".$row1->pend_terakhir."</td>
		                <td>".$row1->nama_sekolah_universitas."</td>
		                <td>".$jurusan."</td>
		                <td>".$row1->nama_kepsek."</td>
                        <td>".$row1->no_ijazah."</td>
                        <td><div align=center>".YMD2DMY(trimTime($row1->tgl_ijazah), TGL_SEPARATOR)."</div></td>";
		                if ($ro==false) {
		                    $s .= "
		                    <td><div align='center'> <a href='".base_url()."index.php/pendidikan/form_edit/".$row1->idspg_pendidikan."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>";
                            //if($this->input->post('page'))   
		                    $s .= "<td><div align='center'><a href=\"javascript:deleteRow(".$row1->idspg_pendidikan.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
		                }
		                $s .= "
		              </tr>";
		
		                $i++;
                	} //foreach
                } else {
                	continue;
                }

            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_pendidikan($form_id, $form_action, $arr=array()) {
        	//format tgl_ijazah harus YMD
        	if (isset($arr['tgl_ijazah'])) {
        		$a = explode(TGL_SEPARATOR, trimTime($arr['tgl_ijazah']));
	        	$d = $a[2] * 1;
	        	$m = $a[1] * 1;
	        	$y = $a[0];
        	} else {
	        	$d = date("j");
	        	$m = date("n");
	        	$y = date("Y");
        	}
        	
        	$ret = "
			<form id=\"".$form_id."\" action=\"".$form_action."\" method=\"post\">
			<fieldset >
			<table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
			  <tr>
			    <td class=\"kolom\" valign=\"top\">NIP</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\"><input type=\"text\" name=\"nip\" id=\"nip\" value=\"".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."\" /></td>
			  </tr>
			  <tr>
			    <td class=\"kolom\" valign=\"top\">Pendidikan</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\">".combo_jenjang_pendidikan('nama', (isset($arr['nama'])?$arr['nama']:""))."</td>
			  </tr>
			  <tr>
			    <td class=\"kolom\" valign=\"top\">Sekolah/Universitas</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\"><input type=\"text\" size=\"38\" id=\"nama_sekolah_universitas\" name=\"nama_sekolah_universitas\" value=\"".(isset($arr['nama_sekolah_universitas'])?$arr['nama_sekolah_universitas']:"")."\" /></td>
			  </tr>
			  <tr>
			    <td class=\"kolom\" valign=\"top\">Nomor Ijazah</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\"><input type=\"text\" size=\"38\" id=\"no_ijazah\" name=\"no_ijazah\" value=\"".(isset($arr['no_ijazah'])?$arr['no_ijazah']:"")."\" /></td>
			  </tr>
			  <tr>
              	<td class='fieldname' valign=\"top\">Tanggal Ijazah</td>
		        <td valign=\"top\">:</td>
		        <td>".combo_tanggal('d',$d,'')."-".
        	          combo_bulan('m',$m,'').
        	          "-<input name='y' id='y' type='text' size='6' value='$y'/>
          			  <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
        		</td>
    		  </tr>
			  <tr>
			    <td class=\"kolom\" valign=\"top\">Nama Kepala Sekolah/Universitas</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\"><input type=\"text\" size=\"38\" name=\"nama_kepsek\" id=\"nama_kepsek\" value=\"".(isset($arr['nama_kepsek'])?$arr['nama_kepsek']:"")."\" /></td>
			  </tr>
			  <tr>
			    <td class=\"kolom\" valign=\"top\">Jurusan</td>
			    <td valign=\"top\">:</td>
			    <td valign=\"top\"><input type=\"text\" size=\"38\" name=\"nama_jurusan\" id=\"nama_jurusan\" value=\"".(isset($arr['nama_jurusan'])?$arr['nama_jurusan']:"")."\" /></td>
			  </tr>
			  <tr>
			    <td valign=\"top\">&nbsp;</td>
			    <td valign=\"top\">&nbsp;</td>
			    <td valign=\"top\">
			      <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
			      <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
			    </td>
			  </tr>
			</table>
			</fieldset>
			</form>
			  ";
        	
        	return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('pendidikan', $arr);
                
            } else {
                $this->db->where('idspg_pendidikan', $id);
                $this->db->update('pendidikan', $arr);
            }
        }
        
	}
?>